package com.home.controller.system.basic;

import com.home.entity.Department;
import com.home.entity.RespBean;
import com.home.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/basic/department")
public class DepartmentController {

    @Autowired
    private DepartmentService departmentService;


    @GetMapping("/")
    public List<Department> getAllDepartments() {
        return departmentService.getAllDepartments();
    }

    @PostMapping("/")
    public RespBean addDept(@RequestBody Department department) {
        String msg = departmentService.addDept(department);
        if (msg == null) {
            return RespBean.error("新增部门失败");
        } else {
            return RespBean.ok(msg);
        }
    }

    @DeleteMapping("/{id}")
    public RespBean deleteById(@PathVariable Integer id) {
        String msg = departmentService.deleteById(id);
        if (msg == null) {
            return RespBean.error("删除部门失败");
        } else {
            return RespBean.ok(msg);
        }
    }

}
